﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HotelManager.DataAccess.Abstract;
using HotelManager.DataAccess.Model;

namespace HotelManager.DataAccess.Concrete
{
    public class LocationRepository : ILocationRepository
    {
        public List<Country> GetAllCountries()
        {
            using (var context = new HotelDbEntities())
            {
                var list = context.Countries.Where(x => x.IsActive).ToList();
                return list;
            }
        }

        public List<City> GetCitiesByCountry(int countryId)
        {
            using (var context = new HotelDbEntities())
            {
                var list = context.Cities
                    .Where(x => x.IsActive && x.CountryId == countryId)
                    .ToList();
                return list;
            }
        }
        public bool AddContact(ContactModel contact)
        {
            try
            {
                using (var context = new HotelDbEntities())
                {
                    Feedback feed = new Feedback
                    {
                        Name = contact.name,
                        Email = contact.email,
                        Message = contact.message
                    };
                    context.Feedbacks.Add(feed);
                    context.SaveChanges();
                    return true;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
